<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Nhan
 * Date: 8/13/12
 * Time: 9:04 PM
 * To change this template use File | Settings | File Templates.
 */
/*
 * Random post widget
 */
class random_post_widget extends WP_Widget {
    function __construct() {
        $paras = array(
            'description'=>'Hiển thị số bài đăng ngẫu nhiên tùy chọn',
            'name'=>'Bài Đăng Ngẫu Nhiên',
        );
        parent::__construct('random_post_widget','',$paras);
    }
    public function form($instance) {
        extract($instance);
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('title');?>">Tiêu đề:</label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id('title');?>"
            name="<?php echo $this->get_field_name('title'); ?>"
            value= "<?php if(isset($title)) echo esc_attr($title);?>" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('posts_to_show');?>">Số bài cho hiển thị: </label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id('posts_to_show');?>"
                   name="<?php echo $this->get_field_name('posts_to_show'); ?>"
                   value="<?php if(isset($posts_to_show)) echo esc_attr($posts_to_show); ?>" />
        </p>
    <?php }
    public function widget($args,$instance) {
        extract($args);
        extract($instance);
        echo $before_widget;
            echo $before_title.$title.$after_title;
            /*
             * LOOP
             */
        if(empty($posts_to_show) || strcmp($posts_to_show,'')==0) $posts_to_show = '5';
            global $post;
            $args = array(
                'posts_per_page'=>$posts_to_show,
                'orderby'=>'rand'
            );
            $random = new WP_Query($args);
        ?>

        <div class="random-post">
        <ul id="1">


        <?php if($random->have_posts()) : while($random->have_posts()) : $random->the_post(); ?>

                <li>
                <div class="random-item">
            <?php
                    $postid = get_the_id();
                    $phongtrong = get_post_meta($postid,'_phongtrong',true);
                    $giaphong = get_post_meta($postid,'_giaphong',true);
                    $gioitinh = get_post_meta($postid,'_gioitinh',true);
                    if(strcmp($gioitinh,'nam') == 0) $gioitinh = 'Nam';
                    elseif(strcmp($gioitinh,'nu') == 0) $gioitinh = 'Nữ';
                    else $gioitinh = "Nam & Nữ";

                    if(strcmp($phongtrong,'')==0) $phongtrong = "chưa updated";
                    if(strcmp($giaphong,'')==0) $giaphong = "chưa updated";
                    /*
                    * Display thumbnail
                    */
                    if ( has_post_thumbnail() )
                        the_post_thumbnail(array(60,60));
                    else echo 'Hình chưa được tải lên';
                    ?>
                    <div class="random-item-info">
                        <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                        <p>
                            <span class="random-item-price"><?php echo $giaphong; ?>/tháng </span>
                            | <span class="random-item-location"><?php
                            $categories = get_the_category();
                            $seperator = '';
                            $output = '';
                            if($categories){
                                foreach($categories as $category) {
                                    $quan =  substr($category->cat_name,0,6);
                                    if (convert_cyr_string($quan,"w","i")== convert_cyr_string("Quận","w","i"))
                                        $output .= '<a href="'.get_category_link($category->term_id ).'" title="' . esc_attr( sprintf( __( "Xem các bài đăng với thẻ %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$seperator;
                                        echo trim($output, $seperator);
                                    }

                                }
                            ?></span>
                        </p>
                        <p>
                            <span class="random-item-empty">Còn trống:</span><span class="random-item-empty"> <?php if(strcmp($phongtrong,'')==0) echo "Chưa cập nhật"; else echo $phongtrong; ?></span>
                            | <span class="random-item-gender"><?php echo $gioitinh; ?></span>
                        </p>
                    </div>

                </div><!--end random-item-->
            </li>
        <?php
              endwhile; else : echo "<p>Chưa có nhà trọ nào được đăng!</p>"; endif;
              wp_reset_query();
        ?>
        <ul>
        </div><!--end random-post-->
        <?php echo $after_widget;
    }
}

add_action('widgets_init','random_post_widget_register');
function random_post_widget_register() {
    register_widget('random_post_widget');
}

/*-----------------------------------------------------------------------------------*/
// This starts the Subscribe Box widget.
/*-----------------------------------------------------------------------------------*/

add_action( 'widgets_init', 'subscribebox_load_widgets' );

function subscribebox_load_widgets() {
    register_widget( 'SubscribeBox_Widget' );
}

class SubscribeBox_Widget extends WP_Widget {

    function SubscribeBox_Widget() {
        /* Widget settings. */
        $para = array(
            'name'=>'Đăng Kí Nhận Mail Update',
            'description'=>"Gửi Email cập nhật khi có bài viết mới qua feed burner"
        );
        parent::__construct('SubscribeBox_Widget','',$para);
    }

    function widget( $args, $instance ) {
        extract( $args );
        extract($instance);

        /* Before widget (defined by themes). */
        echo $before_widget;

        /* Display the widget title if one was input (before and after defined by themes). */
        echo $before_title . $title . $after_title;
        ?>

            <form action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=<?php echo get_option('solostream_fb_feed_id'); ?>', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true">
                <input type="hidden" value="<?php echo $feedid; ?>" name="uri"/>
                <input type="hidden" name="loc" value="en_US"/>
                <p class="email-form">
                    <input type="text" class="sub" name="email" value="<?php _e("Nhập địa chỉ email", "solostream"); ?>" onfocus="if (this.value == '<?php _e("Nhập địa chỉ Email", "solostream"); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e("Nhập địa chỉ Email", "solostream"); ?>';}" /><input type="submit" value="<?php _e("hit", "solostream"); ?>" class="subbutton" />
                </p>
            </form>
        <?php
        /* After widget (defined by themes). */
        echo $after_widget;
    }

    function form( $instance ) {
        extract($instance);
        ?>
        <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Tiêu đề - widget:', "nhan_theme"); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php if(isset($title)) echo esc_attr($title); ?>" />
        </p>
        <p><label for="<?php echo $this->get_field_id( 'feedid' ); ?>"><?php _e('Feedburner ID:', "nhan_theme"); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'feedid' ); ?>" value="<?php if(isset($feedid)) echo esc_attr($feedid); ?>" />
        </p>
    <?php
    }
}

class nhan_custom_display_menu extends WP_Widget {
    function __construct() {
        $paras = array(
            'name'=>'Display Option Menu',
            'description'=>'Hiển thị menu-item tùy ý, nhập vào tên menu muốn hiển thị!'
        );
        parent::__construct('nhan_custom_display_menu','',$paras);
    }
    function form($instance) {
        extract($instance);
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('title'); ?>">Tiêu đề: </label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
                   name="<?php echo $this->get_field_name('title'); ?>"
                   value="<?php if(isset($title)) echo esc_attr($title); ?>" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('menu_name'); ?>">Tên Menu: </label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id('menu_name'); ?>"
                   name="<?php echo $this->get_field_name('menu_name'); ?>"
                   value="<?php if(isset($menu_name)) echo esc_attr($menu_name); ?>" />
        </p>
    <?
    }
    function widget($args,$instance) {
        extract($instance);
        extract($args);
        echo $before_widget;
            echo $before_title.$title.$after_title;
        ?>
    <?php
            $defaults = array(
            'menu'            => $menu_name,
            'container'       => 'div',
            'container_class' => 'widget-bottom',
            'items_wrap'      => '<ul id="%1$s" class="%2$s ">%3$s</ul>',
        ); ?>

        <?php wp_nav_menu( $defaults ); ?>
    <?php
        echo $after_widget;
    }
}

add_action('widgets_init','nhan_custom_display_menu_register');
function nhan_custom_display_menu_register() {
    register_widget('nhan_custom_display_menu');
}
/*
 * Get recent comment widget
 */
class nhan_recent_comment_widget extends WP_Widget {
    function __construct() {
        $paras = array(
            'name'=>"Bình luận mới nhất",
            'description'=>"Hiển thị số bình luận mới nhất"
        );
        parent::__construct('nhan_recent_comment_widget','',$paras);
    }
    function form($instance) {
        extract($instance);
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('title'); ?>">Tiêu đề: </label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
                   name="<?php echo $this->get_field_name('title'); ?>"
                   value="<?php if(isset($title)) echo esc_attr($title); ?>" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('num_comment_show'); ?>">Số lượng Comment: </label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id('num_comment_show'); ?>"
                   name="<?php echo $this->get_field_name('num_comment_show'); ?>"
                   value="<?php if(isset($num_comment_show)) echo esc_attr($num_comment_show); ?>" />
        </p>

    <?php }

    function widget($args,$instance) {
        extract($args);
        extract($instance);
        if(strcmp($num_comment_show,'') ==0 || !is_int($num_comment_show)) $num_comment_show = 5;
        $pre_HTML ="";
        $post_HTML ="";
        global $wpdb;
        $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_author_email, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,100) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT $num_comment_show";

        $comments = $wpdb->get_results($sql);
        $output = $pre_HTML;
        $output .= "\n<ul>";
        foreach ($comments as $comment) {
            $output .= "\n<li><a href=\"" . get_permalink($comment->ID)."#comment-" . $comment->comment_ID . "\" title=\"on ".$comment->post_title . "\">" . strip_tags($comment->comment_author) .": " . "<span class='commentExceprt'>".strip_tags($comment->com_excerpt)."</span></a></li>";
        }
        $output .= "\n</ul>";
        $output .= $post_HTML;
        echo $before_widget;
            echo $before_title.$title.$after_title;
            echo $output;
        echo $after_widget;
    }


}
add_action('widgets_init','nhan_recent_comment_widget_register');
function  nhan_recent_comment_widget_register() {
    register_widget('nhan_recent_comment_widget');
}
/*
 * search multi category widget
 */

class nhan_filter_multicategory extends WP_Widget {
    function __construct() {
        $paras = array(
            'name'=>'Search đa categories',
            'description'=>'Search nhiều categories 1 lúc'
        );
        parent::__construct('nhan_filter_multicategory','',$paras);
    }
    function form($instance) {
        extract($instance);
        ?>
    <p>
        <label for="<?php echo $this->get_field_id('title'); ?>">Tiêu đề: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
               name="<?php echo $this->get_field_name('title'); ?>"
               value="<?php if(isset($title)) echo esc_attr($title); ?>" />
    </p>
    <?php
    }
    function widget($args,$instance) {
        extract($instance);
        extract($args);
        echo $before_widget;
            echo $before_title.$title.$after_title;
            include('searchform.php');
        echo $after_widget;
    }
}

add_action('widgets_init','nhan_filter_multicategory_register');
function nhan_filter_multicategory_register() {
    register_widget('nhan_filter_multicategory');
}

/*
 * Facebook fanpage widget
 */
class nhan_facebook_fanpage extends WP_Widget {
    function __construct() {
        $paras = array(
            'name'=>'Facebook Fanpage - Cóc trọ',
            'description'=>'Hiển thị facebook fanpage - likebox | http://www.facebook.com/HouseForStudent | Height:300, Width:310'
        );
        parent::__construct('nhan_facebook_fanpage','',$paras);
    }
    function form($instance) {
        extract($instance);
        ?>
    <p>
        <label for="<?php echo $this->get_field_id('title'); ?>">Tiêu đề: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
               name="<?php echo $this->get_field_name('title'); ?>"
               value="<?php if(isset($title)) echo esc_attr($title); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('fanpage_link'); ?>">Fanpage Link: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('fanpage_link'); ?>"
               name="<?php echo $this->get_field_name('fanpage_link'); ?>"
               value="<?php if(isset($title)) echo esc_attr($fanpage_link); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('fanpage_width'); ?>">Widget-Width: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('fanpage_width'); ?>"
               name="<?php echo $this->get_field_name('fanpage_width'); ?>"
               value="<?php if(isset($title)) echo esc_attr($fanpage_width); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('fanpage_height'); ?>">Widget-Height: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('fanpage_height'); ?>"
               name="<?php echo $this->get_field_name('fanpage_height'); ?>"
               value="<?php if(isset($title)) echo esc_attr($fanpage_height); ?>" />
    </p>
    <?php
    }
    function widget($args,$instance) {
        extract($instance);
        extract($args);
        echo $before_widget;
        echo $before_title.$title.$after_title;
        ?>
    <div class="fb-like-box" data-href="<?php echo $fanpage_link; ?>" data-width="<?php echo $fanpage_width; ?>" data-height="<?php echo $fanpage_height; ?>" data-show-faces="true" data-stream="false" data-header="false"></div>
        <?php
        echo $after_widget;
    }
}

add_action('widgets_init','nhan_facebook_fanpage_register');
function nhan_facebook_fanpage_register() {
    register_widget('nhan_facebook_fanpage');
}

/*
 * Yahoo Online - technical support
 */

class nhan_contact_info_widget extends WP_Widget {
    function __construct() {
        $paras = array(
            'name'=>"Online Contact - Kỹ Thuật",
            'description'=>"Yahoo, mail, ect..."
        );
        parent::__construct('nhan_contact_info_widget','',$paras);
    }
    function form($instance) {
        extract($instance);
        ?>
    <p>
        <label for="<?php echo $this->get_field_id('title'); ?>">Tiêu đề: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
               name="<?php echo $this->get_field_name('title'); ?>"
               value="<?php if(isset($title)) echo esc_attr($title); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('name1'); ?>">Tên 1: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('name1'); ?>"
               name="<?php echo $this->get_field_name('name1'); ?>"
               value="<?php if(isset($name1)) echo esc_attr($name1); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('yahoo_id1'); ?>">Yahoo ID 1: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('yahoo_id1'); ?>"
               name="<?php echo $this->get_field_name('yahoo_id1'); ?>"
               value="<?php if(isset($yahoo_id1)) echo esc_attr($yahoo_id1); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('yahoo_icon1'); ?>">Thứ tự của icon Yahoo 1: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('yahoo_icon1'); ?>"
               name="<?php echo $this->get_field_name('yahoo_icon1'); ?>"
               value="<?php if(isset($yahoo_icon1)) echo esc_attr($yahoo_icon1); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('email_id1'); ?>">E-mail 1: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('email_id1'); ?>"
               name="<?php echo $this->get_field_name('email_id1'); ?>"
               value="<?php if(isset($email_id1)) echo esc_attr($email_id1); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('name2'); ?>">Tên 2: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('name2'); ?>"
               name="<?php echo $this->get_field_name('name2'); ?>"
               value="<?php if(isset($name2)) echo esc_attr($name2); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('yahoo_id2'); ?>">Yahoo ID 2: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('yahoo_id2'); ?>"
               name="<?php echo $this->get_field_name('yahoo_id2'); ?>"
               value="<?php if(isset($yahoo_id2)) echo esc_attr($yahoo_id2); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('yahoo_icon2'); ?>">Thứ tự của icon Yahoo 2: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('yahoo_icon2'); ?>"
               name="<?php echo $this->get_field_name('yahoo_icon2'); ?>"
               value="<?php if(isset($yahoo_icon2)) echo esc_attr($yahoo_icon2); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('email_id2'); ?>">E-mail 2: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('email_id2'); ?>"
               name="<?php echo $this->get_field_name('email_id2'); ?>"
               value="<?php if(isset($email_id2)) echo esc_attr($email_id2); ?>" />
    </p>
    <img src="<?php bloginfo('template_url'); ?>/images/ym_status.jpg" alt="Yahoo status" />

    <?php }

    function widget($args,$instance) {
        extract($args);
        extract($instance);

        echo $before_widget;
            echo $before_title.$title.$after_title;
        ?>
        <?php if(isset($yahoo_id1) && isset($email_id1) &&strcmp($yahoo_id1,"") !=0) {?>
        <ul class="online-contact-info user1">
            <h4><?php echo $name1; ?></h4>
            <?php if(isset($yahoo_id1)&&strcmp($yahoo_id1,"") !=0)  { ?>
            <li>
                <span>Yahoo:</span> <a id= "yahoo1" href="ymsgr:sendIM?<?php echo $yahoo_id1; ?>"><img src="http://opi.yahoo.com/online?u=<?php echo $yahoo_id1; ?>&amp;m=g&amp;t=<?php echo $yahoo_icon1; ?>" border="0" alt="" /></a>
            </li>
            <?php } ?>
            <?php if(isset($email_id1)&&strcmp($email_id1,"") !=0)  { ?>
            <li>
                <span>E-Mail: </span><?php echo $email_id1; ?>
            </li>
            <?php } ?>
        </ul><!--end user1-->
        <?php } ?>

    <?php if(isset($yahoo_id2) && isset($email_id2) &&strcmp($yahoo_id2,"") !=0) {?>
        <ul class="online-contact-info user2">
            <h4><?php echo $name2; ?></h4>
            <?php if(isset($yahoo_id2)&&strcmp($yahoo_id2,"") !=0)  { ?>
            <li>
                <span>Yahoo:</span> <a id= "yahoo2" href="ymsgr:sendIM?<?php echo $yahoo_id2; ?>"><img src="http://opi.yahoo.com/online?u=<?php echo $yahoo_id2; ?>&amp;m=g&amp;t=<?php echo $yahoo_icon2; ?>" border="0" alt="" /></a>
            </li>
            <?php } ?>
            <?php if(isset($email_id2)&&strcmp($email_id2,"") !=0)  { ?>
            <li>
                <span>E-Mail: </span><?php echo $email_id2; ?>
            </li>
            <?php } ?>
        </ul><!--end user1-->
        <?php } ?>

        <?php echo $after_widget;
    }
}

add_action('widgets_init','nhan_contact_info_widget_register');
function  nhan_contact_info_widget_register() {
    register_widget('nhan_contact_info_widget');
}

/*
 * Yahoo Online - nha tro info support
 */

class nhan_contact_info_widget1 extends WP_Widget {
    function __construct() {
        $paras = array(
            'name'=>"Online Contact - Nhà Trọ",
            'description'=>"Yahoo, mail, ect..."
        );
        parent::__construct('nhan_contact_info_widget1','',$paras);
    }
    function form($instance) {
        extract($instance);
        ?>
    <p>
        <label for="<?php echo $this->get_field_id('title'); ?>">Tiêu đề: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
               name="<?php echo $this->get_field_name('title'); ?>"
               value="<?php if(isset($title)) echo esc_attr($title); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('name1'); ?>">Tên 1: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('name1'); ?>"
               name="<?php echo $this->get_field_name('name1'); ?>"
               value="<?php if(isset($name1)) echo esc_attr($name1); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('yahoo_id1'); ?>">Yahoo ID 1: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('yahoo_id1'); ?>"
               name="<?php echo $this->get_field_name('yahoo_id1'); ?>"
               value="<?php if(isset($yahoo_id1)) echo esc_attr($yahoo_id1); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('yahoo_icon1'); ?>">Thứ tự của icon Yahoo 1: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('yahoo_icon1'); ?>"
               name="<?php echo $this->get_field_name('yahoo_icon1'); ?>"
               value="<?php if(isset($yahoo_icon1)) echo esc_attr($yahoo_icon1); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('email_id1'); ?>">E-mail 1: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('email_id1'); ?>"
               name="<?php echo $this->get_field_name('email_id1'); ?>"
               value="<?php if(isset($email_id1)) echo esc_attr($email_id1); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('name2'); ?>">Tên 2: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('name2'); ?>"
               name="<?php echo $this->get_field_name('name2'); ?>"
               value="<?php if(isset($name2)) echo esc_attr($name2); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('yahoo_id2'); ?>">Yahoo ID 2: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('yahoo_id2'); ?>"
               name="<?php echo $this->get_field_name('yahoo_id2'); ?>"
               value="<?php if(isset($yahoo_id2)) echo esc_attr($yahoo_id2); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('yahoo_icon2'); ?>">Thứ tự của icon Yahoo 2: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('yahoo_icon2'); ?>"
               name="<?php echo $this->get_field_name('yahoo_icon2'); ?>"
               value="<?php if(isset($yahoo_icon1)) echo esc_attr($yahoo_icon2); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('email_id2'); ?>">E-mail 2: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('email_id2'); ?>"
               name="<?php echo $this->get_field_name('email_id2'); ?>"
               value="<?php if(isset($email_id2)) echo esc_attr($email_id2); ?>" />
    </p>
    <img src="<?php bloginfo('template_url'); ?>/images/ym_status.jpg" alt="Yahoo status" />

    <?php }

    function widget($args,$instance) {
        extract($args);
        extract($instance);

        echo $before_widget;
        echo $before_title.$title.$after_title;
        ?>
    <?php if(isset($yahoo_id1) && isset($email_id1) &&strcmp($yahoo_id1,"") !=0) {?>
        <ul class="online-contact-info user3">
            <h4><?php echo $name1; ?></h4>
            <?php if(isset($yahoo_id1)&&strcmp($yahoo_id1,"") !=0)  { ?>
            <li>
                <span>Yahoo:</span> <a id= "yahoo3" href="ymsgr:sendIM?<?php echo $yahoo_id1; ?>"><img src="http://opi.yahoo.com/online?u=<?php echo $yahoo_id1; ?>&amp;m=g&amp;t=<?php echo $yahoo_icon1; ?>" border="0" alt="" /></a>
            </li>
            <?php } ?>
            <?php if(isset($email_id1)&&strcmp($email_id1,"") !=0)  { ?>
            <li>
                <span>E-Mail: </span><?php echo $email_id1; ?>
            </li>
            <?php } ?>
        </ul><!--end user1-->
        <?php } ?>

    <?php if(isset($yahoo_id1) && isset($email_id1)&&strcmp($yahoo_id2,"") !=0) {?>
        <ul class="online-contact-info user4">
            <h4><?php echo $name2; ?></h4>
            <?php if(isset($yahoo_id2)&&strcmp($yahoo_id2,"") !=0)  { ?>
            <li>
                <span>Yahoo:</span> <a id= "yahoo4" href="ymsgr:sendIM?<?php echo $yahoo_id2; ?>"><img src="http://opi.yahoo.com/online?u=<?php echo $yahoo_id2; ?>&amp;m=g&amp;t=<?php echo $yahoo_icon2; ?>" border="0" alt="" /></a>
            </li>
            <?php } ?>
            <?php if(isset($email_id2)&&strcmp($email_id2,"") !=0)  { ?>
            <li>
                <span>E-Mail: </span><?php echo $email_id2; ?>
            </li>
            <?php } ?>
        </ul><!--end user1-->
        <?php } ?>

    <?php echo $after_widget;
    }
}

add_action('widgets_init','nhan_contact_info_widget1_register');
function  nhan_contact_info_widget1_register() {
    register_widget('nhan_contact_info_widget1');
}

/*
 * Latest news widget
 */
class nhan_latest_news_widget extends WP_Widget {
    function __construct() {
        $paras = array(
            'name'=>"Tin tức mới nhất",
            'description'=>"Hiển thị tin tức mới nhất"
        );
        parent::__construct('nhan_latest_news_widget','',$paras);
    }
    function form($instance) {
        extract($instance);
        ?>
    <p>
        <label for="<?php echo $this->get_field_id('title'); ?>">Tiêu đề: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
               name="<?php echo $this->get_field_name('title'); ?>"
               value="<?php if(isset($title)) echo esc_attr($title); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('num_news_show'); ?>">Số tin tức hiển thị: </label>
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('num_news_show'); ?>"
               name="<?php echo $this->get_field_name('num_news_show'); ?>"
               value="<?php if(isset($num_news_show)) echo esc_attr($num_news_show); ?>" />
    </p>

    <?php }

    function widget($args,$instance) {
        extract($args);
        extract($instance);

        if(strcmp($num_news_show,'') == 0 || !isset($num_news_show) ) $num_news_show = 5;
        echo $before_widget;
            echo $before_title.$title.$after_title;
        ?>
        <ul>
            <?php
            global $post;
            $args = array(
                'posts_per_page'=>$num_news_show,
                'post_type'=>'tintuc'
            );
            $latest_news = new WP_Query($args);
            if($latest_news->have_posts()) : while($latest_news->have_posts()) : $latest_news->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
            <?php endwhile; else: echo "Chưa có tin được đăng!"; endif; ?>
                <?php wp_reset_query(); ?>
            </ul>
       <?php echo $after_widget;
    }
}
add_action('widgets_init','nhan_latest_news_widget_register');
function  nhan_latest_news_widget_register() {
    register_widget('nhan_latest_news_widget');
}


